﻿using System;

namespace DO.DreamOnTrader.Quote
{
	/// <summary>
	/// 接收當日回補報價tick的類別
	/// </summary>
	public class RecoverTickBuilder : RecoverTickLoader, ITickBuilder
	{
		public RecoverTickBuilder(Product _product, int _addQuoteMonth = 0, int _filterMinute = 30)
			: base(_product, _addQuoteMonth, _filterMinute) { }

		/// <summary>
		/// 存取前一個tick的交易月份來判斷是否換月
		/// </summary>
		private string lastTradeMonth = "";

		protected override void proecessTick(Tick tick)
		{
			if (BuildingTick != null)
				BuildingTick(tick);
			if (tick.CloseMonth != lastTradeMonth)
			{
				if (BuildingNewTick != null && lastTradeMonth != "")
					BuildingNewTick(tick);
				lastTradeMonth = tick.CloseMonth;
			}
		}

		protected override void toEndQuote()
		{
			if (EndQuote != null)
				EndQuote(null, EventArgs.Empty);
		}

		#region TickBuilder 成員

		public event BuildingTickEventHandler BuildingTick;

		public event BuildingNewTickEventHandler BuildingNewTick;

		#endregion

		#region QuoteBuilder 成員

		public event EndQuoteEventHandler EndQuote;

		#endregion

	}
}
